﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Web.Script.Serialization;
using System.IO;
using MySQLAccess;

namespace WeiboSite
{
    /// <summary>
    /// Summary description for test
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class test : System.Web.Services.WebService
    {
        SQL sql = new SQL();
        [WebMethod]
        public string HelloWorld()
        {
            DataTable dt = sql.RunSQL("select * from WEIBO_RAW");
            JavaScriptSerializer js = new JavaScriptSerializer();
            string retJSON = js.Serialize(dt.Rows[0]["content"]);
            return retJSON;
        }
        [WebMethod]
        public object getWeiboComments(int weibo_id)
        {
            WeiboComments comments = WeiboDB.getWeiboComments(weibo_id);

            return JsonHelper.JsonSerializer<WeiboComments>(comments);
        }
        [WebMethod]
        public object getLatestWeibo(int num)
        {
            WeiboList list = WeiboDB.getLatestWeibo(num);
            return JsonHelper.JsonSerializer<WeiboList>(list);

        }
        [WebMethod]
        public void GetPicNew(string file, string fileData)
        {   
             string rootDir = Server.MapPath("~/");
            try
            {
               
                string fileName = rootDir+"pic\\" + file;
                File.WriteAllBytes(fileName, Convert.FromBase64String(fileData));
            }
            catch (Exception e)
            {
                File.WriteAllText(rootDir+"pic\\log.txt", e.StackTrace+"\n"+e.Message);
            }
        }
 
    }
}
